//
// Created by longyunbo on 7/20/21.
//

#include "JavaNativeInterface.h"
#include "../oops/MethodInfo.h"
#include "../utilties/common.h"
#include <sstream>
#include <string>

string ltos(long l)
{
    ostringstream os;
    os<<l;
    string result;
    istringstream is(os.str());
    is>>result;
    return result;
}



MethodInfo* JavaNativeInterface::getMethodID(InstanceKlass* klass , string name , string descriptorName ){

    //找到main方法
    //得到方法集合
    INFO_PRINT(" methodLength %d \n" , klass->getmethodLength() );
    for( int i = 0 ; i < klass->getmethodLength() ; i++  ){
        MethodInfo* m=&(klass->getMethodInfo()[i]);
        //得到方法名
        char* methodNa =(char*)klass->get_constantPool()->get_item(m->getnameIndex());
//        printf(" descriptorIndex  %s \n" , methodName );
        //得到方法描述
        char* desName =(char *)klass->get_constantPool()->get_item(m->getdescriptorIndex());
        printf(" methodName %s descriptor %s \n" , methodNa , desName );
        if( name == methodNa && desName && desName ){
            INFO_PRINT(" 找到main方法 ");
            return m;
        }

    }

    ERROR_PRINT(" 没有找到方法 {} #{} " , name.c_str() , descriptorName.c_str() );
    return nullptr;

};

